home *** CD-ROM | disk | FTP | other *** search
- #include <exec/memory.h>
- #include <dos/dosextens.h>
- #include <dos/dostags.h>
- #ifdef __GNUC__
- #include <inline/exec.h>
- #include <inline/dos.h>
- #endif
- #include <stabs.h>
-
- extern struct WBStart *_WBenchMsg;
- extern char *__commandline;
- extern struct DosLibrary *DOSBase;
- extern struct ExecBase *SysBase;
- extern void *__SaveSP;
- extern char __dosname[];
-
- extern long __stack;
- extern char *__procname;
- extern long __priority;
-
- /* I must close a library after my child is running -
- * and closing a library requires a working dispatcher, so:
- */
- static struct SignalSemaphore *sem;
-
- void __initdetach(void)
- {
- if(_WBenchMsg!=NULL)
- return;
-
- if(sem!=NULL) /* I must be the child process */
- { ObtainSemaphore(sem); /* Assert that my parent is already dead */
- ReleaseSemaphore(sem);
- FreeMem(sem,sizeof(struct SignalSemaphore));
- return;
- }
- /* I must be the parent */
- if((sem=(struct SignalSemaphore *)
- AllocMem(sizeof(struct SignalSemaphore),MEMF_PUBLIC|MEMF_CLEAR))==NULL)
- exit(20);
-
- InitSemaphore(sem);
-
- ObtainSemaphore(sem); /* Assert that my child is suspended until I'm finished */
-
- if((DOSBase=(struct DosLibrary *)OpenLibrary(__dosname,37))!=NULL)
- { struct CommandLineInterface *cli;
- void *stack;
-
- cli=Cli();
- { struct TagItem tags[7];
-
- tags[0].ti_Tag =NP_Seglist; /* child process gets my seglist */
- tags[0].ti_Data=cli->cli_Module;
-
- tags[1].ti_Tag =NP_FreeSeglist; /* and must free it */
- tags[1].ti_Data=1;
-
- tags[2].ti_Tag =NP_StackSize; /* it gets a stack */
- tags[2].ti_Data=__stack;
-
- tags[3].ti_Tag =NP_Name; /* a name */
- tags[3].ti_Data=(ULONG)__procname;
-
- tags[4].ti_Tag =NP_Priority; /* a priority */
- tags[4].ti_Data=__priority;
-
- tags[5].ti_Tag =NP_Arguments; /* and my commandline Arguments */
- tags[5].ti_Data=(ULONG)__commandline;
-
- tags[6].ti_Tag =TAG_END; /* That's all - everything else is implicit */
-
- stack=__SaveSP;
-
- if(CreateNewProc(tags)!=NULL)
- { cli->cli_Module=0; /* I'm no longer owner of this */
- CloseLibrary((struct Library *)DOSBase);
- DOSBase=NULL;
-
- Forbid(); /* Disable Multitasking */
- ReleaseSemaphore(sem);
-
- /* Adjust stack, enable multitasking, return 0 */
- asm("movel %0,sp;movel %1,a6;moveql #0,d0;jmp a6@(-138)"::
- "r"(stack),"r"(SysBase):"a6");
- }
- CloseLibrary((struct Library *)DOSBase);
- }
- }
- ReleaseSemaphore(sem);
-
- exit(20);
- }
-
- ADD2INIT(__initdetach,-70); /* A very high priority */
-